From 65002208b990bded0cdb0469f9422471e0b4de27 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 2 Nov 2011 14:30:23 +0100 Subject: [PATCH] win32: Ensure newly mapped toplevels are inside the workarea This is what e.g. metacity does, and its needed to e.g. get the inital position of the gimp dock window right. --- gdk/win32/gdkwindow-win32.c | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/gdk/win32/gdkwindow-win32.c b/gdk/win32/gdkwindow-win32.c index f2154abf2f..4985103a01 100644 --- a/gdk/win32/gdkwindow-win32.c +++ b/gdk/win32/gdkwindow-win32.c @@ -1065,6 +1065,57 @@ show_window_internal (GdkWindow *window, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER)); } + if (!already_mapped && + GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL && + !window_impl->override_redirect) + { + /* Ensure new windows are fully onscreen */ + RECT window_rect; + HMONITOR monitor; + MONITORINFO mi; + int x, y; + + GetWindowRect (GDK_WINDOW_HWND (window), &window_rect); + + monitor = MonitorFromWindow (GDK_WINDOW_HWND (window), MONITOR_DEFAULTTONEAREST); + mi.cbSize = sizeof (mi); + if (monitor && GetMonitorInfo (monitor, &mi)) + { + x = window_rect.left; + y = window_rect.top; + + if (window_rect.right > mi.rcWork.right) + { + window_rect.left -= (window_rect.right - mi.rcWork.right); + window_rect.right -= (window_rect.right - mi.rcWork.right); + } + + if (window_rect.bottom > mi.rcWork.bottom) + { + window_rect.top -= (window_rect.bottom - mi.rcWork.bottom); + window_rect.bottom -= (window_rect.bottom - mi.rcWork.bottom); + } + + if (window_rect.left < mi.rcWork.left) + { + window_rect.right += (mi.rcWork.left - window_rect.left); + window_rect.left += (mi.rcWork.left - window_rect.left); + } + + if (window_rect.top < mi.rcWork.top) + { + window_rect.bottom += (mi.rcWork.top - window_rect.top); + window_rect.top += (mi.rcWork.top - window_rect.top); + } + + if (x != window_rect.left || y != window_rect.top) + API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL, + window_rect.left, window_rect.top, 0, 0, + SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER)); + } + } + + if (window->state & GDK_WINDOW_STATE_FULLSCREEN) { gdk_window_fullscreen (window); -- 2.30.2